package com.example.customview;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class MyTextView extends View {
    private static final String TAG = "MyTextView";
    private Paint paint = new Paint();
    private Canvas canvas;
    private int value;

    public MyTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        paint.setColor(Color.RED);
        paint.setStrokeWidth(5);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setTextSize(100);

        /*ValueAnimator valueAnimator = ValueAnimator.ofInt(0,500);
        valueAnimator.setDuration(5000);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                value = (int) animation.getAnimatedValue();
                invalidate();
            }
        });

        valueAnimator.setRepeatCount(-1);
        valueAnimator.start();*/



    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Log.e(TAG,"onDraw");
        /*//画线条
        canvas.drawLine(100,100,300,300,paint);*/
       /* //画矩阵
        canvas.drawRect(300,300,500,500,paint);*/
       /*//画圆形
        canvas.drawCircle(300,300,100,paint);*/
        /*//画扇形
        RectF oval = new RectF(100,100,300,300);
       canvas.drawArc(oval,0,90,true,paint);

       //文字
       canvas.drawText("i like china",200,500,paint);*/
        /*Path path = new Path();
        path.lineTo(100,200);
        path.lineTo(100,300);
        //路径
        canvas.drawPath(path,paint);*/

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.meinv);

        Matrix matrix1 = new Matrix();
        matrix1.setScale(0.5f, 0.5f);
        matrix1.postTranslate(50, 0);
        canvas.drawBitmap(bitmap, matrix1, paint);

        Matrix matrix2 = new Matrix();
        matrix2.setScale(-0.5f, 0.5f);
        matrix2.postTranslate(500, 0);
        canvas.drawBitmap(bitmap, matrix2, paint);

        Matrix matrix3 = new Matrix();
        matrix3.setScale(0.5f, -0.5f);
        matrix3.postTranslate(50, 450);
        canvas.drawBitmap(bitmap, matrix3, paint);

        Matrix matrix4 = new Matrix();
        matrix4.setScale(-0.5f, -0.5f);
        matrix4.postTranslate(500, 450);
        canvas.drawBitmap(bitmap, matrix4, paint);
    }
}
